<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="班级" prop="classId">
        <el-select
          v-model="queryParams.classId"
          filterable
          clearable
          placeholder="请选择班级"
        >
          <el-option
            v-for="item in queryClazzList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
            size="small"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="groupName">
        <el-input
          v-model.trim="queryParams.groupName"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div class="flex-container">
    <div
      v-for="(item, index) in humanFace"
      :key="index"
      class="table-container"
    >
      <div class="top-container">
        <div class="img">
          <el-image :src="item.img"></el-image>
        </div>
        <div class="name-text">
          <span>{{ item.name }}</span>
          <span>{{ item.sex }} {{ item.age }}岁</span>
        </div>
        <div class="button">
          <el-button type="primary" size="mini" plain>查看</el-button>
        </div>
      </div>
      <div class="bottom-container">
        <span>班级：{{ item.className }}</span>
        <span>入园时间：{{ item.enrollTime }}</span>
      </div>
    </div>
  </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改评教指标对话框 -->
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="菜单组名称" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入菜单组名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addmenugroup,
  delmenugroup,
  listmenugroup,
  updatemenugroup,
} from "@/api/base/wechatmenu";
import { selectClazz } from "@/api/base/clazz";

export default {
  name: "submenupage",
  data() {
    return {
      humanFace: [
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
        {name: "欧阳娜娜",sex: "女",age: "5",className: "幼一班",enrollTime: "10:00",img: "https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng52a120049b7d798dfea8d781affb707598432f05ddc8e151880569194eb783b3",},
      ],
      imageSrc: "图片地址", // 替换为实际图片地址
      age: "5",
      className: "幼一班",
      enrollTime: "10:00",

      // 班级表格数据
      queryClazzList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      submenuList: [],
      // 评教指标树选项
      evalNormOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        groupName: [
          { required: true, message: "菜间组名称不能为空", trigger: "blur" },
        ],
      },
      total: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };
  },
  created() {
    this.getList();
    this.getQueryClazzList();
  },
  methods: {
    /** 查询班级列表 */
    getQueryClazzList() {
      this.loading = true;
      var p = { status: "1" };
      if (this.queryParams.year) p.year = this.queryParams.year;
      if (this.queryParams.specId) p.specId = this.queryParams.specId;
      selectClazz(p).then((response) => {
        this.queryClazzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询评教指标列表 */
    async getList() {
      try {
        this.loading = true;
        const data = await listmenugroup(this.queryParams);
        this.submenuList = data.rows;
        this.total = data.total;
        this.loading = false;
      } catch (e) {
        console.log(e);
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        groupName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加菜单组名称";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = JSON.parse(JSON.stringify(row));
      this.open = true;
      this.title = "修改菜单组名称";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatemenugroup(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addmenugroup(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delmenugroup(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
  },
};
</script>
<style scoped>
.flex-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
}
.table-container {
  width: 267px;
  height: 128px;
  border-radius: 4px;
  border: 1px solid #dddddd;
  margin: 16px 14px 16px 14px;
}
.top-container {
  display: flex;
}
.img {
  width: 56px;
  height: 56px;
  margin-top: 20px;
  margin-left: 20px;
}
.name-text {
  width: 64px;
  margin-top: 26px;
  margin-left: 17px;
  /* padding: 10px; */
}
.name-text span:first-child {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
  line-height: 22px;
  margin-bottom: 6px;
  display: block;
}
.name-text span:last-child {
  display: block;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 20px;
  white-space: pre; /* 保留空格和换行符 */
}
.button {
  margin-left: 43px;
  margin-top: 26px;
}
.bottom-container {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 20px;
  margin-top: 16px;
}
.bottom-container span:first-child {
  margin-left: 20px;
}
.bottom-container span:last-child {
  margin-left: 38px;
  /* margin-top: 16px; */
}
</style>
